package com.house.util;

import com.house.entity.User;
import org.springframework.security.core.context.SecurityContextHolder;

/**
 * 获取当前登录用户的id
 * @author:lzq
 * @date: 2018/5/29 16:32
 */
public class LoginUserUtil {

    public static User load() {
        Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        if (principal != null && principal instanceof User) {
            return (User) principal;
        }
        return null;
    }

    public static Long getLoginUserId(){
        User user = load();
        if(user!=null){
            return user.getId();
        }
        return -1L;
    }

}
